﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Microsoft.Win32;
using OpenPowerPoint;

namespace OpenPresenter
{
    public class Backend : DependencyObject
    {
        public static readonly DependencyProperty PresentationProperty = DependencyProperty.Register("Presentation", typeof(Presentation), typeof(Backend), new PropertyMetadata(null));

        public Presentation Presentation
        {
            get { return (Presentation)GetValue(PresentationProperty); }
            set { SetValue(PresentationProperty, value); }
        }

        public static RoutedUICommand OpenFileCommand { get; private set; }

        static Backend()
        {
            OpenFileCommand = new RoutedUICommand("Open File", "openfile", typeof(Backend));
        }

        public void OpenFile_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        public void OpenFile_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            opf.Title = (string)Application.Current.FindResource("open_file");
            opf.Filter = "OpenXML files|*.pptx";

            if (opf.ShowDialog() == true)
            {
                Presentation = Presentation.LoadPresentation(opf.FileName);
            }
        }
    }
}
